﻿@model IEnumerable<HotelManageSystem.Models.FinanceModel>
<link href= "@Url.Content("~/Content/TelerikGrid.css")"rel="stylesheet" type="text/css" />
<script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $(".DeleteButton").click(function () {
            var id = $(this).attr("deleteId");
            var flag = window.confirm("确认要删除吗?");
            if (flag == true) {
                $.get("/Finance/DeleteFinance/" + id, null, function (data) {
                    $("#content").html(data);
                });
            }
        });
        $(".EditButton").click(function () {
            var id = $(this).attr("editId");
            $.get("/Finance/EditFinance/" + id, null, function (data) {
                $("#content").html(data);
            });
            $.post("HumanResources/SetSeesion", { u: "/Finance/EditFinance/" + id }, function () { });
        });
    });

    //防止Telerik控件经过排序、分页后,新增功能脚本失效
    function onDataBound() {
        $(".DeleteButton").click(function () {
            var id = $(this).attr("deleteId");
            var flag = window.confirm("确认要删除吗?");
            if (flag == true) {
                $.get("/Finance/DeleteFinance/" + id, null, function (data) {
                    $("#content").html(data);
                });
            }
        });
        $(".EditButton").click(function () {
            var id = $(this).attr("editId");
            $.get("/Finance/EditFinance/" + id, null, function (data) {
                $("#content").html(data);
            });
            $.post("HumanResources/SetSeesion", { u: "/Finance/EditFinance/" + id }, function () { });
        });
    }
</script>
@(
 Html.Telerik().Grid(Model)
        .Name("Grid")
        .DataKeys(keys => keys.Add(b => b.Id))
      .DataBinding(dataBinding => dataBinding.Ajax()
            .Select("ManageFinanceAjax", "Finance"))
        .Pageable(paging => paging
            .Style(GridPagerStyles.NextPreviousAndNumeric)
            .Position(GridPagerPosition.Bottom)
            .PageSize(12))
        .Columns(columns =>
        {
            columns.Bound(b => b.Display).Width(300);
            columns.Bound(b => b.Income).Format("{0:0}元").Filterable(false).Width(300);
            columns.Bound(b => b.FinanceDate).Width(300);
            columns.Template(b => @Html.Raw("<input class='DeleteButton' type='button' value='删除' deleteId='" + b.Id + "'/>"
                            + "<input class='EditButton' type='button' value='编辑' editId='" + b.Id + "'/>"))
                             .ClientTemplate("<input class='DeleteButton' type='button' value='删除' deleteId='<#= Id #>'/>"
                            + "<input class='EditButton' type='button' value='编辑' editId='<#= Id #>'/>");
        })
        .Selectable()
        .Filterable()
        .Sortable()
        .ClientEvents(events => events//防止排序、过滤操作之后按钮无法调用脚本
                         .OnDataBound("onDataBound")
                     )
)
